{{extends file="index.html"}}
{{block name = "cssjs"}}
<link rel="stylesheet" href="vendor/select2/select2.min.css">
<link rel="stylesheet" href="vendor/colorpicker/css/colorpicker.css">
<link rel="stylesheet" href="vendor/datepicker/datepicker.css">
<style>
    .form-group{
        margin-top: 30px;
    }
</style>
<script type="text/javascript" src="vendor/select2/select2.full.min.js"></script>
<script type="text/javascript" src="vendor/colorpicker/js/bootstrap-colorpicker.js"></script>
<script type="text/javascript" src="vendor/datepicker/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="vendor/ckfinder/ckfinder.js"></script>
<script type="text/javascript" src="vendor/ckeditor/ckeditor.js"></script>
{{/block}}
{{block name=nav}}编辑文章{{/block}}
{{block name=title}}编辑文章
<hr/>{{/block}}
{{block name=notice}}{{/block}}

{{block name=main}}

<div class="panel panel-info">
    <div class="panel-heading"><span class="glyphicon glyphicon-file" aria-hidden="true"> 编辑文章</span></div>

    <div class="panel-body">
        <form class="form-horizontal" role="form" action="index.php?c=article&a=do_edit&id={{$article.id}}" method="post" enctype="multipart/form-data">
            <div class="row">
                <div class="form-group">
                    <label class="control-label col-md-2" style="text-align: center">所属栏目</label>
                    <div class="col-md-10">
                        <select class="js-example-basic-single" style="width:60%" name="cateid">
                            {{foreach $cates as $cate}}
                            <option value="{{$cate.id}}"
                                     {{if $article.cateId eq $cate.id}}
                                        selected='selected';
                            {{/if}}
                                    >{{$cate.cateName}}</option>
                            {{/foreach}}
                        </select>
                    </div>
                </div>

                <div class="form-group" style="">
                    <label for="title" class="col-md-2" style="text-align: center">标题</label>
                    <div class="col-md-10">
                        <input type="text" class="form-control" id="title"
                               placeholder="文章标题" name="title" style="width:40%" value="{{$article.title}}">
                    </div>
                </div>

                <div class="form-group" style="">
                    <label class="col-md-2" style="text-align: center">标题颜色</label>

                    <div class="controls col-md-10" >
                        <div data-color-format="hex" data-color="{{$article.title_color}}" class="input-append color colorpicker">
                            <input type="text" value="{{$article.title_color}}" class="span6" name="title_color">
	        <span class="add-on">
	            <i style="background-color:#08c;"></i>
	        </span>
                        </div>
                    </div>
                </div>

                <div class="form-group" style="">
                    <label class="col-md-2" style="text-align: center">发布日期</label>

                    <div class="controls  col-md-10">
                        <input type="text" data-date-format="yyyy-mm-dd" value="{{date('Y-m-d', time())}}" name="time"
                               class="datepicker span6">
                    </div>
                </div>

                <div class="form-group" style="">
                    <label for="desc" class="col-md-2" style="text-align: center">描述</label>
                    <div class="controls  col-md-10">
                        <input type="text" class="form-control" id="desc" name="desc"
                               placeholder="文章描述" value="{{$article.desc}}" style="width: 50%;">
                    </div>
                </div>

                <div class="form-group" style="">
                    <label for="summary" class="col-md-2" style="text-align: center">摘要</label>
                    <div class="controls  col-md-10">
                        <textarea name="summary"  id="summary" placeholder="文章摘要" style="width: 50%;height:100px">
                            {{$article.summary}}
                        </textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label" style="text-align: center">缩略图</label>
                    <div class="controls  col-md-10">
                        <input type="text"  id="thumb1" class="form-control" style="width:40%;" name="pic_path" value="{{$article.pic_path}}">
                        <button class="btn btn-success" type="button" id="ckfinder-modal-1"
                                onclick="BrowseServer('thumb1','img_show1');">上传</button>
                        <button class="btn btn-danger thumb_del1" type="button">删除</button>
                        <img src=" {{$article.pic_path}} " id="img_show1" width="90px" height="90px" class="img_s p4"/>
                    </div>
                </div>

                <div class="form-group add">
                    <label class="col-md-2 control-label" style="text-align: center">新增附件</label>
                    <div class="controls  col-md-10">
                        <button class="btn btn-warning add_file" type="button">增加</button>
                    </div>
                </div>
                {{foreach $fujian as $k=>$v}}
                <div class="form-group file">
                    <label class="col-md-2 control-label" style="text-align: center">附件({{$k+1}})</label>
                    <div  class="controls  col-md-10">
                        <input type="text" class="" style="width:30%;" id="file1" name="attach_path[]" value="{{$v}}">
                        <button class="btn btn-success" type="button" onclick="BrowseServerFile('file1')" id="">上传</button>
                        {{if $k eq 0}}
                        <button class="btn btn-danger file_del1" type="button">删除</button>
                        {{else}}
                        <button class="btn btn-danger file_del" type="button">删除</button>
                        {{/if}}
                    </div>
                </div>
                {{/foreach}}
                <div class="editor">
                    <textarea name="content" class="">{{$article.content}}</textarea>
                </div>
                <br/>
                <div class="col-md-4 col-md-offset-5">
                    <button class="btn btn-success" type="submit">提交</button>
                    <button class="btn btn-danger" type="submit">返回</button>
                </div>
            </div>
        </form>

    </div>
</div>


<script>
    CKEDITOR.replace('content',
            {
                filebrowserBrowseUrl: '/vendor/ckfinder/ckfinder.html',
                filebrowserImageBrowseUrl: '/vendor/ckfinder/ckfinder.html?type=Images',
                filebrowserFlashBrowseUrl: '/vendor/ckfinder/ckfinder.html?type=Flash',
                filebrowserUploadUrl: '/vendor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
                filebrowserImageUploadUrl: '/vendor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
                filebrowserFlashUploadUrl: '/vendor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
            });

    function BrowseServer(thumb1,img_show1) {
        var finder = new CKFinder();

        //当选中图片时执行的函数
        finder.selectActionFunction = function(fileUrl){
            $("#"+thumb1).val(fileUrl);
            $("#"+img_show1).attr("src",""+fileUrl+"");
        }
        finder.popup();//调用窗口
    }

    function BrowseServerFile(file1) {
        var finder = new CKFinder();
        finder.selectActionFunction = function(fileUrl){

            $("#"+file1).val(fileUrl);
        } //当选中图片时执行的函数
        finder.popup();//调用窗口
    }

    $(function () {
        $(".js-example-basic-single").select2();
        $(".colorpicker").colorpicker();
        $(".datepicker").datepicker();

        $(".add_file").click(function(){
            var i=$('.file').size();
            var n = i+1;
            var html = '<div class="form-group file">'+
                    '<label class="control-label col-md-2" style="text-align: center">附件('+n+'):</label>'+
                    '<div class="controls col-md-10">'+
                    '<input type="text" id="file'+n+'" class="span5" name="attach_path[]" style="width:30%;"/>&nbsp;'+
                    "<input type='button'  value='上 传' onclick=BrowseServer('file"+n+"') class='btn btn-success' />&nbsp;"+
                    '<input type="button"  value="删 除" class="file_del btn btn-danger" />&nbsp;'+
                    '</div>'+
                    '</div>';

            if(n < 6) {
                $(".file:last").after(html);
            } else {
                alert("您最多只能添加5个附件！");
                return false;
            }
            $(this).blur();  //失去焦点
            return false;   //不跳转
        });

        //删除缩微图附件
        $(".thumb_del1").click(function(){
            $("#thumb1").val('');
            $("#img_show1").attr("src",'');
        });

        $(document).on("click",".file_del",function(){
            $(this).parent().parent().remove();
        });

        $(".file_del1").click(function(){
            $("#file1").val('');
        });


    });

</script>


{{/block}}